/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.ove.openmath.jome.ctrl.amto;

/**
 *
 * @author Mr.Sam
 */
import fr.ove.openmath.jome.ctrl.linear.events.LinearParserEvent;
import fr.ove.openmath.jome.ctrl.amto.Function;

/**
* The abstract math tree object of the limit operator.
*
* @author © 2000 DIRAT Laurent
* @version 1.0  25/02/2000
*/
public class Limit extends Function {
    /**
    * The constructor.
    */
    public Limit() {
        super("limit");
    }
    
    /**
    * "Flushes" the object as a sequence of events for the building of the model
    */
    public void flush() {
        LinearParserEvent linearParserEvent = new LinearParserEvent(getEventSource());
        // Le format est la borne, suivit du tye de la limite, suivie de la lambda expression
        // Le type détermine le paramètre à envoyer avec l'opening
        
        // The opening
        linearParserEvent.setToken(opening, (String) ((AbstractMathTreeObject) getChild(1)).getParameter());
        fireLinearParserEvent(linearParserEvent);
        
        // On envoie l'objet de la lambda expression, i.e. ce qu'on fait tendre vers la borne
        AbstractMathTreeObject lambda = (AbstractMathTreeObject) getChild(2);
        int index = lambda.getNbChildren() - 1;
        flushChild(lambda.getChild(index), index);
        
        // Un séparateur
        linearParserEvent.setToken(token, null);
        fireLinearParserEvent(linearParserEvent);
        
        // La viariable liée, i.e. la variable que l'on fait tendre vers la borne
        flushChild(lambda.getChild(0), 0);
                
        // Un séparateur
        linearParserEvent.setToken(token, null);
        fireLinearParserEvent(linearParserEvent);
        
        // La borne
        flushChild(getChild(0), 0);

        // The closing
        linearParserEvent.setToken(closing, null);
        fireLinearParserEvent(linearParserEvent);
    }
}